package com.imstlife.vending.activity;

import android.app.Application;
import android.util.Log;

import com.imstlife.vending.R;
import com.imstlife.vending.push.ServiceManager;
import com.imstlife.vending.sgy.logger.LocalLog;
import com.imstlife.vending.utils.SharePersistentUtil;

import java.util.HashMap;
import java.util.Map;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by lihaifeng on 16/11/10.
 */
public class MyApplication extends Application {

    private  static  MyApplication ins;

    public static Map<String,Long> outTradeHistory = new HashMap<String,Long>();

    /**
     * 推送服务管理
     */
    private ServiceManager serviceManager;

    @Override
    public void onCreate() {
        super.onCreate();
        SharePersistentUtil.saveSharePersistent(this, "adminPassword","95367248");
        SharePersistentUtil.saveSharePersistent(this,"tradedata","");
        String str = SharePersistentUtil.getSharePersistentString(this,"spnum");
        if (str!=null&&!str.equals("")){

        }else{
            SharePersistentUtil.saveSharePersistent(this,"spnum","1");
        }
        initService();
        LocalLog.init(true, 20, "vending");
        LocalLog.e("app","start");
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        String registrationId = JPushInterface.getRegistrationID(this);
    }


/**
 * 启动推送服务
 */
    private void initService() {

        ins = this;
        // Start the service
        serviceManager = new ServiceManager(this);
        serviceManager.setNotificationIcon(R.mipmap.ic_launcher);
        serviceManager.startService();
        Log.i("lhf", "启动推送服务");

    }

    public static MyApplication getInstance(){
        return ins;
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        serviceManager.stopService();
    }
}
